package com.auth0.jwt;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.auth0.jwt.algorithms.Algorithm;

public class JWTCreatorTest {

	public static void main(String[] args) throws Exception {
		/*Map<String, Object> header = new HashMap<String, Object>();
        header.put("typ", "JWT");
        String signed = JWTCreator.init()
                .withHeader(header)
                .withClaim("unique", "+8618510626368")
                .withClaim("name", "测试红包上传1")
                .withClaim("count", 2)
                .withClaim("begin", JWTCreatorTest.getSecondTimes())
                .withClaim("expiry", 7)
                .withClaim("iat", (int)(System.currentTimeMillis()/1000-30))
                .withClaim("exp", (int)(System.currentTimeMillis()/1000+300))
                .sign(Algorithm.HMAC256("5DC5F734E2568A53AA9C1279D1B96"));
        System.out.println("https://wechat.car2go.cn/coupon/get/?jwt="+signed);*/
		getState();
	}
	public static String getSecondTimes(){
		//createTime
		Date now = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(now);
		calendar.add(Calendar.DATE, 1);
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");// 可以方便地修改日期格式
		String nowTime = dateFormat.format(now);
		Date now2 = calendar.getTime();
		String nowTime2 = dateFormat.format(now2);
		System.out.println(nowTime2);
		System.out.println(nowTime);
		return nowTime2;
	}
	public static boolean getState()throws Exception {
		Map<String, Object> header = new HashMap<String, Object>();
        header.put("typ", "JWT");
        String signed = JWTCreator.init()
                .withHeader(header)
                .withClaim("unique", "+8618510626368")
                .withClaim("iat", (int)(System.currentTimeMillis()/1000-30))
                .withClaim("exp", (int)(System.currentTimeMillis()/1000+300))
                .sign(Algorithm.HMAC256("5DC5F734E2568A53AA9C1279D1B96"));
        System.out.println("https://wechat.car2go.cn/coupon/checkuser?jwt="+signed);
        return true;
	}
}
